﻿@{
    ViewBag.Title = "选择部门";
}
@model FMS.UI.Areas.Admin.ViewModel.Department
@section headsecion{
    <style type="text/css">
        select {
            height: 200px;
            width: 110px;
        }
        .tbList {
            text-align: center;
            border: 1px solid #ddd;
            border-collapse: collapse;
            margin: 0px;
            padding: 0px;
            width: 100%;
            border-top-width: 0px;
            border-bottom-width: 0px;
            border-left-width: 0px;
            border-right-width: 0px;
        }
            .tbList td, th {
                border: 1px solid #ddd;
                padding: 0px 5px;
            }
            .tbList td {
               border:0px solid white;margin-bottom:0px;
            }
    </style>
    <script type="text/javascript">
        $(function () {
            $("#ddlCompany").change(compChange);
            $("#ddlDepartment").dblclick(moveRight);
            $("#moveDepartment").dblclick(removeLeft);

            $("#btnSet").click(btnSend);
        });
        //加载公司列表
        function compChange() {
            //公司id
            var compId = this.value;
            //去请求点击后的部门列表
            $.get("/admin/usr/GetDeparmentNames", "compId=" + compId, function (jsonData) {
                var $ddlDepartment = $("#ddlDepartment");
                var $ddlMoveDepartment = $("#moveDepartment");
                $ddlDepartment.children().remove();
                $ddlMoveDepartment.children().remove();
                $.each(jsonData.Data, function (i, dep) {
                    $ddlDepartment.append("<option value=\"" + dep.depId + "\">" + dep.depName + "</option>");
                });
            }, "json");
        }

        //将选中的 角色 移到 用户角色下拉框中
        function moveRight() {
            var $oldDepartment = $("#moveDepartment option");
            //获取新选中的 部门选项
            var $selectedDepartment = $("#ddlDepartment option:checked");
            $selectedDepartment.each(function () {
                var sel = this;
                var selid = document.getElementById("moveDepartment").options.length;
                if (selid < 1) {
                    $("#moveDepartment").append(sel);
                }
                else {
                    $.msgBoxObj.showInfo("只能选择一个部门");
                }
            });
        }

        function removeLeft() {
            var $selectedDepartment = $("#moveDepartment option:checked");
            $selectedDepartment.each(function () {
                var sel = this;
                $("#ddlDepartment").append(sel);
            });

        }

        function btnSend() {
            var $sendDepartment = $("#moveDepartment option");

            var selid = document.getElementById("moveDepartment").options.length;
            if (selid == 0) {
                $.msgBoxObj.showInfo("请选择部门");
            }
            else {
                //获取后台的iframe到前台empDepIdName
                var a = $("#moveDepartment").text();
                var b = $("#moveDepartment").val();
                $("#comiframe", parent.document.body).contents().find("#empDepIdName").val(a).focus().attr("class","valid");
                $("#comiframe", parent.document.body).contents().find("#empDepId").val(b);

                $.globalHelper.closeDepCommon();
            }

        }
    </script>

}



    <table class="tbList">
        <tr >
            <td>公司名称</td>
            <td>部门名称</td>
            <td>选择部门</td>
        </tr>
        <tr>
            <td>
                <select id="ddlCompany" multiple="multiple" name="compName">
                    @foreach (var item in ViewBag.CompList as IEnumerable<FMS.Model.Company>)
                    {
                        <option value="@item.compId">@item.compName</option>
                    }
                </select>
            </td>
            <td>
                <select id="ddlDepartment" multiple="multiple">
                    @if (ViewBag.DepList != null)
                    {
                        @*foreach (var item in ViewBag.DepList as IEnumerable<FMS.Model.Department>)
                        {
                            <option value="@item.depId"> @item.depName</option>
                        }*@
                    }
                </select>
            </td>
            <td>
                <select id="moveDepartment" multiple="multiple" name="selectdep"></select>
            </td>
        </tr>
        <tr>
            <td colspan="3" >
                <input type="submit" value="确定" id="btnSet" name="btnSet" style="height: 27px; width: 56px; margin-top: 6px" />
            </td>
        </tr>
    </table>


